layui.define(['conf'], function (exports) {
    const {conf} = layui;
    exports("file_uploader", {
        render: function (data) {
            $(data.elem).html(`
                <div class="layui-form-item">
                    <label class="layui-form-label">${data.title}</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="${data.name}" value="" class="field-${data.name}">
                        <button type="button" class="layui-btn layui-btn-normal" id="${data.name}Button">文件上传</button>
                        <br><br>
                        <p class="${data.name}Result">未上传</p>
                    </div>
                    <div class="layui-form-mid layui-word-aux" >${data.desc || ''}</div>
                </div>`);

            var load;
            return upload.render({
                elem: "#" + data.name + "Button",
                url: data.url || conf.api.url.upload, //此处配置你自己的上传接口即可
                field: 'file',
                exts: data.exts,
                multiple: false,
                choose: function () {
                    $('input[name="' + data.name + '"]').val('');
                },
                before: function (obj) {
                    load = layer.load();
                },
                done: function (res) {
                    layer.close(load);
                    //上传完毕
                    $('input[name="' + data.name + '"]').val(res.data.file);
                    $("#" + data.name + "Result").text("已上传");

                    layer.msg('上传成功！');
                }
            });
        }
    });
});